(function(angular) {
	'use strict';
	angular.module('fs.waf').controller('apf.popup.payment.buyBackType',buyBackTypeController);
	buyBackTypeController.$inject = [ '$scope', '$q', '$uibModalInstance', 'Constants', 'ajaxServiceFactory', 'dialogsModule', 'gridService', 'modalService', 'layoutConfig', 'validatorConfig', '$filter', 'authService' ];
	function buyBackTypeController($scope, $q, $uibModalInstance, Constants, ajaxServiceFactory, dialogsModule, gridService, modalService, layoutConfig, validatorConfig, filter, authService) {
		var ctrl = this;
		ctrl.dialogsModule = dialogsModule;
		ctrl.layoutConfig = layoutConfig;
		ctrl.validatorConfig = validatorConfig;
		ctrl.buyBackTypeModel = {};
		ctrl.buyBackTypeModel.label ="label.payment.";
		
		ctrl.ok = function() {
			if(ctrl.buyBackTypeModel.buyBackType == "DAY"){
				if(ctrl.buyBackTypeModel.earlyPayDay && ctrl.buyBackTypeModel.earlyPayDay <= 0 ){
					modalService.openErrorDialogs({
						'messages' : [ {msg : 'validation.minvalue.notequal', args : [filter('translate')('label.payment.earlypayday'), 0]} ]
					});
					return;
				}
			}
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['ok'] || dialogsModule.btnCallback['ok']([{"buyBackType" : angular.toJson(ctrl.buyBackTypeModel)}]) !== false) {
				$uibModalInstance.close();
			}
		};
		ctrl.close = function() {
			if (!dialogsModule.btnCallback || !dialogsModule.btnCallback['close'] || dialogsModule.btnCallback['close']() !== false) {
				$uibModalInstance.dismiss();
			}
		};
		
		ctrl.init = function() {
			ctrl.buyBackTypeOptions =
				[{"label" : "label.buybackautoType.day", "value" : "DAY"},
				 {"label" : "label.buybacktype.n", "value" : "NONE"}];
			if(dialogsModule.params.buyBackType){
				ctrl.buyBackTypeModel = angular.fromJson(dialogsModule.params.buyBackType);
			};
		};
	}
})(angular);
